package com.msl.base.service;

import com.msl.base.dao.LabelDao;
import com.msl.base.pojo.Label;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.IdWorker;

import java.util.List;

/**
 * @ProjectName: tensquare_parent03
 * @Package: com.msl.base.service
 * @ClassName: LaberService
 * @Author: Messi
 * @Date: 2020/7/30 21:25
 * @Version: 1.0
 */
@Service
public class LabelService {

    @Autowired
    private LabelDao labelDao;
    @Autowired
    private IdWorker idWorker;

    /**
     * 查询所有
     * @return
     */
    public List<Label> findAll(){
        return labelDao.findAll();
    }

    /**
     * 根据id查询标签
     * @param id
     * @return
     */
    public Label findById(String id){
        return labelDao.findById(id).get();
    }

    /**
     * 增加标签
     * @param label
     */
    public void add(Label label){
        label.setId(idWorker.nextId()+"");
        labelDao.save(label);
    }

    /**
     * 根据id删除标签
     * @param id
     */
    public void deleteById(String id){
        labelDao.deleteById(id);
    }

    /**
     * 修改
     * @param label
     */
    public void update(Label label){
        label.setFans(labelDao.findById(label.getId()).get().getFans());
        labelDao.save(label);
    }
}
